package com.waidi.clothespad.adapter;
import java.util.ArrayList;  
import android.content.Context;  
import android.graphics.drawable.Drawable;  
import android.view.Gravity;  
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.ImageView;  
import android.widget.LinearLayout;  
import android.widget.TextView;

import com.waidi.clothespad.R;

public class GridAdapter extends BaseAdapter {  
    private ArrayList<String> mNameList = new ArrayList<String>();  
    private ArrayList<Drawable> mDrawableList = new ArrayList<Drawable>();  
    private LayoutInflater mInflater;  
    private Context mContext;  
    LinearLayout.LayoutParams params;  
  
    public GridAdapter(Context context, ArrayList<String> nameList, ArrayList<Drawable> drawableList) {  
        mNameList = nameList;  
        mDrawableList = drawableList;  
        mContext = context;  
        mInflater = LayoutInflater.from(context);  
          
        params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);  
        params.gravity = Gravity.CENTER;  
    }  
  
    public int getCount() {  
        return mNameList.size();  
    }  
  
    public Object getItem(int position) {  
        return mNameList.get(position);  
    }  
  
    public long getItemId(int position) {  
        return position;  
    }  
  
    public View getView(int position, View convertView, ViewGroup parent) {  
        ItemViewTag viewTag;  
          
        if (convertView == null)  
        {  
            convertView = mInflater.inflate(R.layout.gridview_item, null);
              
            // construct an item tag  
            viewTag = new ItemViewTag((TextView) convertView.findViewById(R.id.text_des), (TextView) convertView.findViewById(R.id.text_num));
            convertView.setTag(viewTag);
        } else  
        {  
            viewTag = (ItemViewTag) convertView.getTag();  
        }  
          
        // set name  
        viewTag.mName.setText(mNameList.get(position));
          
        // set icon  
       // viewTag.mIcon.setBackgroundDrawable(mDrawableList.get(position));
        viewTag.mIcon.setLayoutParams(params);
        return convertView;  
    }  
      
    class ItemViewTag  
    {  
        protected TextView mIcon;
        protected TextView mName;  
          
        /** 
         * The constructor to construct a navigation view tag 
         *  
         * @param name 
         *            the name view of the item 
         *
         *            the size view of the item 
         * @param icon 
         *            the icon view of the item 
         */  
        public ItemViewTag(TextView icon, TextView name)
        {  
            this.mName = name;  
            this.mIcon = icon;  
        }  
    }  
  
} 